import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';

typedef NavigationBackCallback = void Function();

class BaseAppBar extends AppBar {
  static const double spacing = NavigationToolbar.kMiddleSpacing;

  BaseAppBar(
    BuildContext context,
    Widget title, {
    bool isCenterTitle = true,
    bool isShowLeading = true,
    double titleSpacing = spacing,
    double elevation = 0.5,
    final Brightness brightness = Brightness.light,
    final Color backColor = Colors.black,
    final Color backgroundColor = Colors.white,
    final Widget leading,
    final List<Widget> actions,
    final NavigationBackCallback backCallback,
  }) : super(
            // bottom: PreferredSize(
            //     child: Container(
            //       color: Colors.grey.shade300,
            //       width: double.infinity,
            //       height: 0.5,
            //     ),
            //     preferredSize: Size.fromHeight(1)),
            title: title,
            leading: isShowLeading
                ? leading != null
                    ? leading
                    : InkWell(
                        onTap: () {
                          backCallback != null
                              ? backCallback()
                              : LRouter.navigatorCtx(context).pop(null);
                        },
                        splashColor: Colors.transparent,
                        highlightColor: Colors.transparent,
                        child: Container(
                            width: 40,
                            alignment: Alignment.centerLeft,
                            padding:
                                EdgeInsets.only(left: ScreenAdapter.width(15)),
                            child: Icon(
                              Icons.arrow_back_ios_rounded,
                              color: backColor,
                            )))
                : null,
            actions: actions != null ? actions : null,
            backgroundColor: backgroundColor,
            elevation: elevation,
            centerTitle: isCenterTitle,
            brightness: brightness,
            titleSpacing: titleSpacing);
}
